import BaseView from "../../../cfw/mvc/BaseView";
import SmallGameController from "../SmallGameController";
import FillColorV1 from "../../../engine/comps/FillColorV1";
import SDKManager from "../../../sdk/SDKManager";
import CaptureComp from "../../../engine/comps/CaptureComp";
import { MAX_STATE_NUM } from "../../../public/Config";
import SmallGameManager from "../SmallGameManager";
import ModuleManager, { ModuleID } from "../../../cfw/module/ModuleManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class FillColorRoomView extends BaseView {


    @property([cc.SpriteFrame])
    pictures: cc.SpriteFrame[] = []

    @property(cc.Sprite)
    fillSprite: cc.Sprite = null;

    @property(FillColorV1)
    fillColor: FillColorV1 = null;

    @property(cc.Sprite)
    colorSprite: cc.Sprite = null;

    @property(CaptureComp)
    capture: CaptureComp = null;

    protected controller: SmallGameController;
    protected model: SmallGameManager;
    start() {
        this.controller = SmallGameController.instance();
        this.fillSprite.spriteFrame = this.pictures[this.controller.getFillColorIndex()]
    }
    onDestroy() {
        super.onDestroy()
        ModuleManager.getLoader(ModuleID.SMALL_GAME).release()
    }
    changeColor(color: cc.Color) {
        cc.log(' color ', color)
        this.colorSprite.node.color = color;
    }

    onButtonHomeClick() {
        this.controller.gotoLobbyScene()
    }


    onButtonConfirmClick() {
        this.model.addNum(MAX_STATE_NUM / 4)
        this.model.updateExp()
        if (SDKManager.getChannel().cantUseImageDataURL()) {
            this.controller.back(this.capture.getTextureInfo());
        } else {
            this.controller.back(this.capture.getDataUrl());
        }

    }


}
